/*SCY'S TO DO LIST OH MY GOD
1. COMMENT THE SHIT OUT OF EVERYTHING.
2. Rebuild messenger to work with all factions, and admin chat based on variables within one function.
3. Start Vehicle Framework, possible dynamic license plates based on car ID???
4. Is PlayerInCar even fucking used? figure out if it's used, if it is...get rid of it. what an awful function..
5. Create a ToggleFrozen function, to work with tazing, and admin systems, and whatever else we want....((MAYBE A BLACKOUT SYSTEM IF YOU GET IN TO BIG OF A CRASH? OH MY GOD THAT'S BRILLIANT.))
6. learn the tazer commands, and what they do and how to utilize them.
// Will update this list once things are completed
7. Add a name checker on player connect.
*/
//--------------------------------------
//--             includes             --
//--------------------------------------
#include <a_samp>
#include <sscanf2> //check commands
//#include <zcmd> // COMMAND:lololol
#include <YSI\y_commands> //Let's try Y COMMANDS.
#include <YSI\y_ini> //INI system
#include <foreach> //foreach(player,i)
#include <OPSP> //OnPlayerShootPlayer
//--------------------------------------
//--             defines              --
//--------------------------------------
//---------------dialogs----------------
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_SUCCESS_1 3
#define DIALOG_SUCCESS_2 4
//--------------end dialogs-------------
//----------------factions--------------
#define     CIVI          1
#define     POLICE        2
#define     FIRE          3
#define     GOV           4
//--------------end factions------------

//----------------colors---------------- BY killer98p
#define COL_WHITE "{FFFFFF}"
#define COL_RED "{F81414}"
#define COL_GREEN "{00FF22}"
#define COL_LIGHTBLUE "{00CED1}"
// System Defined Colors
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_ACTIVEBORDER 0xB4B4B4FF
#define COLOR_ACTIVECAPTION 0x99B4D1FF
#define COLOR_ACTIVECAPTIONTEXT 0x000000FF
#define COLOR_ALICEBLUE 0xF0F8FFFF
#define COLOR_ANTIQUEWHITE 0xFAEBD7FF
#define COLOR_APPWORKSPACE 0xABABABFF
#define COLOR_AQUA 0x00FFFFFF
#define COLOR_AQUAMARINE 0x7FFFD4FF
#define COLOR_AZURE 0xF0FFFFFF
#define COLOR_BEIGE 0xF5F5DCFF
#define COLOR_BISQUE 0xFFE4C4FF
#define COLOR_BLACK 0x000000FF
#define COLOR_BLANCHEDALMOND 0xFFEBCDFF
#define COLOR_BLUE 0x0000FFFF
#define COLOR_BLUEVIOLET 0x8A2BE2FF
#define COLOR_BROWN 0xA52A2AFF
#define COLOR_BURLYWOOD 0xDEB887FF
#define COLOR_BUTTONFACE 0xF0F0F0FF
#define COLOR_BUTTONHIGHLIGHT 0xFFFFFFFF
#define COLOR_BUTTONSHADOW 0xA0A0A0FF
#define COLOR_CADETBLUE 0x5F9EA0FF
#define COLOR_CHARTREUSE 0x7FFF00FF
#define COLOR_CHOCOLATE 0xD2691EFF
#define COLOR_CONTROL 0xF0F0F0FF
#define COLOR_CONTROLDARK 0xA0A0A0FF
#define COLOR_CONTROLDARKDARK 0x696969FF
#define COLOR_CONTROLLIGHT 0xE3E3E3FF
#define COLOR_CONTROLLIGHTLIGHT 0xFFFFFFFF
#define COLOR_CONTROLTEXT 0x000000FF
#define COLOR_CORAL 0xFF7F50FF
#define COLOR_CORNFLOWERBLUE 0x6495EDFF
#define COLOR_CORNSILK 0xFFF8DCFF
#define COLOR_CRIMSON 0xDC143CFF
#define COLOR_CYAN 0x00FFFFFF
#define COLOR_DARKBLUE 0x00008BFF
#define COLOR_DARKCYAN 0x008B8BFF
#define COLOR_DARKGOLDENROD 0xB8860BFF
#define COLOR_DARKGRAY 0xA9A9A9FF
#define COLOR_DARKGREEN 0x006400FF
#define COLOR_DARKKHAKI 0xBDB76BFF
#define COLOR_DARKMAGENTA 0x8B008BFF
#define COLOR_DARKOLIVEGREEN 0x556B2FFF
#define COLOR_DARKORANGE 0xFF8C00FF
#define COLOR_DARKORCHID 0x9932CCFF
#define COLOR_DARKRED 0x8B0000FF
#define COLOR_DARKSALMON 0xE9967AFF
#define COLOR_DARKSEAGREEN 0x8FBC8BFF
#define COLOR_DARKSLATEBLUE 0x483D8BFF
#define COLOR_DARKSLATEGRAY 0x2F4F4FFF
#define COLOR_DARKTURQUOISE 0x00CED1FF
#define COLOR_DARKVIOLET 0x9400D3FF
#define COLOR_DEEPPINK 0xFF1493FF
#define COLOR_DEEPSKYBLUE 0x00BFFFFF
#define COLOR_DESKTOP 0x000000FF
#define COLOR_DIMGRAY 0x696969FF
#define COLOR_DODGERBLUE 0x1E90FFFF
#define COLOR_FIREBRICK 0xB22222FF
#define COLOR_FLORALWHITE 0xFFFAF0FF
#define COLOR_FORESTGREEN 0x228B22FF
#define COLOR_FUCHSIA 0xFF00FFFF
#define COLOR_GAINSBORO 0xDCDCDCFF
#define COLOR_GHOSTWHITE 0xF8F8FFFF
#define COLOR_GOLD 0xFFD700FF
#define COLOR_GOLDENROD 0xDAA520FF
#define COLOR_GRADIENTACTIVECAPTION 0xB9D1EAFF
#define COLOR_GRADIENTINACTIVECAPTION 0xD7E4F2FF
#define COLOR_GRAY 0x808080FF
#define COLOR_GRAYTEXT 0x808080FF
#define COLOR_GREEN 0x008000FF
#define COLOR_GREENYELLOW 0xADFF2FFF
#define COLOR_HIGHLIGHT 0x3399FFFF
#define COLOR_HIGHLIGHTTEXT 0xFFFFFFFF
#define COLOR_HONEYDEW 0xF0FFF0FF
#define COLOR_HOTPINK 0xFF69B4FF
#define COLOR_HOTTRACK 0x0066CCFF
#define COLOR_INACTIVEBORDER 0xF4F7FCFF
#define COLOR_INACTIVECAPTION 0xBFCDDBFF
#define COLOR_INACTIVECAPTIONTEXT 0x434E54FF
#define COLOR_INDIANRED 0xCD5C5CFF
#define COLOR_INDIGO 0x4B0082FF
#define COLOR_INFO 0xFFFFE1FF
#define COLOR_INFOTEXT 0x000000FF
#define COLOR_IVORY 0xFFFFF0FF
#define COLOR_KHAKI 0xF0E68CFF
#define COLOR_LAVENDER 0xE6E6FAFF
#define COLOR_LAVENDERBLUSH 0xFFF0F5FF
#define COLOR_LAWNGREEN 0x7CFC00FF
#define COLOR_LEMONCHIFFON 0xFFFACDFF
#define COLOR_LIGHTBLUE 0xADD8E6FF
#define COLOR_LIGHTCORAL 0xF08080FF
#define COLOR_LIGHTCYAN 0xE0FFFFFF
#define COLOR_LIGHTGOLDENRODYELLOW 0xFAFAD2FF
#define COLOR_LIGHTGRAY 0xD3D3D3FF
#define COLOR_LIGHTGREEN 0x90EE90FF
#define COLOR_LIGHTPINK 0xFFB6C1FF
#define COLOR_LIGHTSALMON 0xFFA07AFF
#define COLOR_LIGHTSEAGREEN 0x20B2AAFF
#define COLOR_LIGHTSKYBLUE 0x87CEFAFF
#define COLOR_LIGHTSLATEGRAY 0x778899FF
#define COLOR_LIGHTSTEELBLUE 0xB0C4DEFF
#define COLOR_LIGHTYELLOW 0xFFFFE0FF
#define COLOR_LIME 0x00FF00FF
#define COLOR_LIMEGREEN 0x32CD32FF
#define COLOR_LINEN 0xFAF0E6FF
#define COLOR_MAGENTA 0xFF00FFFF
#define COLOR_MAROON 0x800000FF
#define COLOR_MEDIUMAQUAMARINE 0x66CDAAFF
#define COLOR_MEDIUMBLUE 0x0000CDFF
#define COLOR_MEDIUMORCHID 0xBA55D3FF
#define COLOR_MEDIUMPURPLE 0x9370DBFF
#define COLOR_MEDIUMSEAGREEN 0x3CB371FF
#define COLOR_MEDIUMSLATEBLUE 0x7B68EEFF
#define COLOR_MEDIUMSPRINGGREEN 0x00FA9AFF
#define COLOR_MEDIUMTURQUOISE 0x48D1CCFF
#define COLOR_MEDIUMVIOLETRED 0xC71585FF
#define COLOR_MENU 0xF0F0F0FF
#define COLOR_MENUBAR 0xF0F0F0FF
#define COLOR_MENUHIGHLIGHT 0x3399FFFF
#define COLOR_MENUTEXT 0x000000FF
#define COLOR_MIDNIGHTBLUE 0x191970FF
#define COLOR_MINTCREAM 0xF5FFFAFF
#define COLOR_MISTYROSE 0xFFE4E1FF
#define COLOR_MOCCASIN 0xFFE4B5FF
#define COLOR_NAVAJOWHITE 0xFFDEADFF
#define COLOR_NAVY 0x000080FF
#define COLOR_OLDLACE 0xFDF5E6FF
#define COLOR_OLIVE 0x808000FF
#define COLOR_OLIVEDRAB 0x6B8E23FF
#define COLOR_ORANGE 0xFFA500FF
#define COLOR_ORANGERED 0xFF4500FF
#define COLOR_ORCHID 0xDA70D6FF
#define COLOR_PALEGOLDENROD 0xEEE8AAFF
#define COLOR_PALEGREEN 0x98FB98FF
#define COLOR_PALETURQUOISE 0xAFEEEEFF
#define COLOR_PALEVIOLETRED 0xDB7093FF
#define COLOR_PAPAYAWHIP 0xFFEFD5FF
#define COLOR_PEACHPUFF 0xFFDAB9FF
#define COLOR_PERU 0xCD853FFF
#define COLOR_PINK 0xFFC0CBFF
#define COLOR_PLUM 0xDDA0DDFF
#define COLOR_POWDERBLUE 0xB0E0E6FF
#define COLOR_PURPLE 0x800080FF
#define COLOR_RED 0xFF0000FF
#define COLOR_ROSYBROWN 0xBC8F8FFF
#define COLOR_ROYALBLUE 0x4169E1FF
#define COLOR_SADDLEBROWN 0x8B4513FF
#define COLOR_SALMON 0xFA8072FF
#define COLOR_SANDYBROWN 0xF4A460FF
#define COLOR_SCROLLBAR 0xC8C8C8FF
#define COLOR_SEAGREEN 0x2E8B57FF
#define COLOR_SEASHELL 0xFFF5EEFF
#define COLOR_SIENNA 0xA0522DFF
#define COLOR_SILVER 0xC0C0C0FF
#define COLOR_SKYBLUE 0x87CEEBFF
#define COLOR_SLATEBLUE 0x6A5ACDFF
#define COLOR_SLATEGRAY 0x708090FF
#define COLOR_SNOW 0xFFFAFAFF
#define COLOR_SPRINGGREEN 0x00FF7FFF
#define COLOR_STEELBLUE 0x4682B4FF
#define COLOR_TAN 0xD2B48CFF
#define COLOR_TEAL 0x008080FF
#define COLOR_THISTLE 0xD8BFD8FF
#define COLOR_TOMATO 0xFF6347FF
#define COLOR_TRANSPARENT 0xFFFFFF00
#define COLOR_TURQUOISE 0x40E0D0FF
#define COLOR_VIOLET 0xEE82EEFF
#define COLOR_WHEAT 0xF5DEB3FF
#define COLOR_WHITE 0xFFFFFFFF
#define COLOR_WHITESMOKE 0xF5F5F5FF
#define COLOR_WINDOW 0xFFFFFFFF
#define COLOR_WINDOWFRAME 0x646464FF
#define COLOR_WINDOWTEXT 0x000000FF
#define COLOR_YELLOW 0xFFFF00FF
#define COLOR_YELLOWGREEN 0x9ACD32FF
#define STEALTH_ORANGE 0xFF880000
#define STEALTH_OLIVE 0x66660000
#define STEALTH_GREEN 0x33DD1100
#define STEALTH_PINK 0xFF22EE00
#define STEALTH_BLUE 0x0077BB00
#define COLOR_INVISIBLE 0xFF000000
//----------------endcolors-------------
//----------------paths-----------------
#define PATH "/Users/%s.ini" //Saves the User data in so and so path.
#define VEHPATH "/Vehicles/%i.ini" //Saves the User data in so and so path.
//---------------end paths---------------
//--------------------------------------
//--             forwards             --
//--------------------------------------
forward LoadUser_data(playerid,name[],value[]);
forward LoadCar_vehicle(vehicleid, name[], value[]);
forward PlayerInCar(playerid, vehicleid);
forward GetCarID(playerid);
forward IsEngineRunning(vehicleid);
forward AreLightsOn(vehicleid);
forward Tazed(playerid);
forward Unfreeze(playerid);
//--------------------------------------
//--            new and enums         --
//--------------------------------------
enum TeamCars  //Faction based cars.
{
t01, t02, t03, t04, t05, t06, t07, t08, t09, t10, t11, t12, t13, t14, t15, t16, t17, t18, t19, t20,
t21, t22, t23, t24, t25, t26, t27, t28, t29, t30, t31, t32, t33, t34, t35, t36, t37, t38, t39, t40,
t41,
}
new Cars[TeamCars]; //How to call faction based cars.

enum pInfo  //These are player variables, password, faction, and position.
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths,
	pFaction,
	pRank,
	pPosX,
	pPosY,
	pPosZ,
	pSkin,
	pWeapon,
	pAmmo,
	pMuted,
}
new PlayerInfo[MAX_PLAYERS][pInfo];//a way to access pInfo
enum cInfo
{
	cModel,
	cOwner[26],
	cLocked,
	cColor1,
	cColor2,
	cPosX,
	cPosY,
	cPosZ,
	cPosRot,
}
new CarInfo[MAX_VEHICLES][cInfo];
new Logged[MAX_PLAYERS];//is the player logged in?
new isPlayerSpectating[MAX_PLAYERS]; //Are you spectating a player?
new PlayerName[50]; //Player Name, I'm sure I can use this alot, so I made it public.
new handsup[MAX_PLAYERS];
new PlayerInVehicle[MAX_PLAYERS];
new aDuty[MAX_PLAYERS]; //Admin Duty
new duty[MAX_PLAYERS]; //Police Duty
new pTazed[MAX_PLAYERS]; // Tazer
new pTazer[MAX_PLAYERS]; // Tazer Command
new Cuffed[MAX_PLAYERS]; //Handcuffs
new Float:specx[MAX_PLAYERS], Float:specy[MAX_PLAYERS], Float:specz[MAX_PLAYERS];
new HandsUp[MAX_PLAYERS];
new TruckerOnJob[MAX_PLAYERS];//Trucker job
new trailervin[MAX_VEHICLES]; // Makes sure that you have the same trailer on trucker job start to finish!
//--------------------------------------
//--           functions              --
//--------------------------------------
public LoadUser_data(playerid,name[],value[])//hey let's load all the player data from the ini
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Int("Faction",PlayerInfo[playerid][pFaction]);
    INI_Int("Rank",PlayerInfo[playerid][pRank]);
    INI_Int("X",PlayerInfo[playerid][pPosX]);
    INI_Int("Y",PlayerInfo[playerid][pPosY]);
    INI_Int("Z",PlayerInfo[playerid][pPosZ]);
    return 1;
}

public LoadCar_vehicle(vehicleid, name[], value[])
{
    INI_Int("Model",CarInfo[vehicleid][cModel]);
    INI_String("Owner",CarInfo[vehicleid][cOwner], 25);
    INI_Int("Locked",CarInfo[vehicleid][cLocked]);
    INI_Int("Color1",CarInfo[vehicleid][cColor1]);
    INI_Int("Color2",CarInfo[vehicleid][cColor2]);
    INI_Int("X",CarInfo[vehicleid][cPosX]);
    INI_Int("Y",CarInfo[vehicleid][cPosY]);
    INI_Int("Z",CarInfo[vehicleid][cPosZ]);
    INI_Int("Rotation",CarInfo[vehicleid][cPosRot]);
	return 1;
}

stock UserPath(playerid) //this sets the path.
{
    new string[128],playername[MAX_PLAYER_NAME];  // MORE VARIABLES.
    GetPlayerName(playerid,playername,sizeof(playername)); //gets the name of the player, then sets it to playername, then sets playername as the length of the playername.
    format(string,sizeof(string),PATH,playername); // Turns the path into PATH = Users/thisisausername.ini
    return string; //returns the valid path.
}
stock VehPath(vehicleid) //this sets the path.
{
    new string[128];  // MORE VARIABLES.
    format(string,sizeof(string), VEHPATH, vehicleid); // Turns the path into PATH = Users/thisisausername.ini
    return string; //returns the valid path.
}
stock udb_hash(buf[]) { //hashes the shit out of passwords.
    new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++)
    {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
}

stock FactionMessenger(faction, string[], color) //This function controls the radio command, and will control the OOC faction chat as well. TODO: see Scy's to do list, number 2
{
    foreach(Player,i)
    {
        if(PlayerInfo[i][pFaction] == faction)
        {
            SendClientMessage(i,color,string);
        }
    }
}

stock ToggleSpectate(playerid, specid)
{
	if(isPlayerSpectating[playerid])
	{
		TogglePlayerSpectating(playerid, 0);
		SetPlayerPos(playerid, specx[playerid], specy[playerid], specz[playerid]);
		isPlayerSpectating[playerid] = 0;
		return 1;
	}
	else if(!isPlayerSpectating[playerid])
	{
		GetPlayerPos(playerid, specx[playerid], specy[playerid], specz[playerid]);
		if(!IsPlayerInAnyVehicle(specid))
		{
			TogglePlayerSpectating(playerid, 1);
			PlayerSpectatePlayer(playerid, specid);
			isPlayerSpectating[playerid] = 1;
			return 1;
		}
		else if(IsPlayerInAnyVehicle(specid))
		{
			new carid = GetPlayerVehicleID(specid);
			TogglePlayerSpectating(playerid, 1);
			PlayerSpectateVehicle(playerid, carid);
			isPlayerSpectating[playerid] = 1;
			return 1;
		}
	}
}

//------------------------------------------------------------------------------------------------------------------
//------------------------------                   CAR FUNCTIONS                       -----------------------------
//------------------------------------------------------------------------------------------------------------------
public PlayerInCar(playerid, vehicleid)//Catalog of what player is in what vehicle at any given time.
{
	if(vehicleid != INVALID_VEHICLE_ID)
	{
		PlayerInVehicle[playerid] = vehicleid;
		return 1;
	}
	else
	{
	return 0;
	}
}

public IsEngineRunning(vehicleid)   // checks to the see if the vehicle is running, you can call like IsEngineRunning(GetCarID(playerid))
{
	if(vehicleid != INVALID_VEHICLE_ID)
		{
		new  engine, lights, alarm, doors, bonnet, boot, objective;
		GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
		if(engine == 1)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	else
	{
		return 0;
	}
 }

 public AreLightsOn(vehicleid)  //Are the lights on? Call like AreLightsOn(GetCarID(playerid)) will return 1 or 0, true or false, respectively.
{
	if(vehicleid != INVALID_VEHICLE_ID)
		{
		new  engine, lights, alarm, doors, bonnet, boot, objective;
		GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
		if(lights == 1)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	else
	{
		return 0;
	}
 }

stock CreateOwnedCar(ownerid, modelid, Float:x, Float:y, Float:z, color1, color2) // PROOF OF CONCEPT, maybe admin command??
{
	new vehiclelol, carowner[MAX_PLAYER_NAME];
	vehiclelol = CreateVehicle(modelid, x, y, z, 0, color1, color2, 7200);
	carowner = GetName(ownerid);
	new INI:File = INI_Open(VehPath(vehiclelol)); //write out all the data to the in
	INI_SetTag(File,"vehicle");
    INI_WriteInt(File, "Model", modelid);
    INI_WriteString(File, "Owner", carowner);
    INI_WriteInt(File, "Locked", 0);
    INI_WriteInt(File, "Color1", color1);
    INI_WriteInt(File, "Color2", color2);
    INI_WriteFloat(File, "X", x);
    INI_WriteFloat(File, "Y", y);
    INI_WriteFloat(File, "Z", z);
    INI_WriteInt(File, "Rotation", 0);
	INI_Close(File);
	INI_ParseFile(VehPath(vehiclelol), "LoadCar_vehicle", .bExtra = true, .extra = vehiclelol);
	return vehiclelol;
}

stock CreateStaticOwnedCar(ownername[25], modelid, Float:x, Float:y, Float:z, Float:rot, color1, color2) // PROOF OF CONCEPT, maybe admin command??
{
	new vehiclelol, carowner;
	strreplace(ownername, '_', ' ');
	vehiclelol = AddStaticVehicleEx(modelid, x, y, z, rot, color1, color2, 86400);
	new INI:File = INI_Open(VehPath(vehiclelol)); //write out all the data to the in
	INI_SetTag(File,"vehicle");
    INI_WriteInt(File, "Model", modelid);
    INI_WriteString(File, "Owner", ownername);
    INI_WriteInt(File, "Locked", 0);
    INI_WriteInt(File, "Color1", color1);
    INI_WriteInt(File, "Color2", color2);
    INI_WriteFloat(File, "X", x);
    INI_WriteFloat(File, "Y", y);
    INI_WriteFloat(File, "Z", z);
    INI_WriteInt(File, "Rotation", 0);
	INI_Close(File);
	INI_ParseFile(VehPath(vehiclelol), "LoadCar_vehicle", .bExtra = true, .extra = vehiclelol);
	return vehiclelol;
}

//------------------------------------------------------------------------------------------------------------------
//------------------------------                  END CAR FUNCTIONS                    -----------------------------
//------------------------------------------------------------------------------------------------------------------
stock AdminMessenger(color, string[]) //This is the admin messenger function TODO: see Scy's to do list, number 2
{
    foreach(Player,i)
    {
        if(PlayerInfo[i][pAdmin] > 0 )
        {
            SendClientMessage(i,color,string);
        }
    }
}

stock strreplace(string[], find, replace) //string replace, give it something to replace and what to replace it with.
{
    for(new i=0; string[i]; i++)
    {
        if(string[i] == find)
        {
            string[i] = replace;
        }
    }
}


stock TogglePlayerHands(playerid)
{
	new string[100];
	if(!HandsUp[playerid])
	{
		format(string, sizeof(string), "Hands up: %i", HandsUp[playerid]);
		SendClientMessage(playerid, COLOR_RED, string);
		ApplyAnimation(playerid, "PED", "handsup", 4.1, 0,1,1,1,1,1);
		HandsUp[playerid] = 1;
		return 1;
	}
	else
	{
		ApplyAnimation(playerid, "CARRY", "crry_prtial", 1.0, 0, 0, 0, 0, 0);
		HandsUp[playerid] = 0;
		return 1;
	}
}

/////////////////////////////////////////////////////////////////////////////////////////

stock GetName(playerid)     //give a playerid, it will return the name without the _
{
    new name[24];
    GetPlayerName(playerid, name, sizeof(name)); //get's the playername, throws it into name, with the size of it.
    strreplace(name, '_', ' '); //replaces the underscore in a name with a space.
    return name; //returns the newly created name, with a space.
}

stock ProxDetector(Float:radi, playerid, string[],color) //proximity detector, very handy.
{
    new Float:x,Float:y,Float:z;
    GetPlayerPos(playerid,x,y,z);
    foreach(Player,i)
    {
        if(IsPlayerInRangeOfPoint(i,radi,x,y,z))
        {
            SendClientMessage(i,color,string);
        }
    }
}



main() //why is this here I don't even.
{
	print("\n----------------------------------");
	print(" Chatford City Roleplay, Rev 24"); // holy fuck, this man already?
	print("----------------------------------\n");
}


public OnGameModeInit()
{
	ShowPlayerMarkers(0);
	SetNameTagDrawDistance(15.0);
 	AddPlayerClass( 46, 1681, 1448, 11, 0, 0,0, 0,0, 0,0 ); // TEAM_ONE
    AddPlayerClass( 280, 2294.9997558594, 2468.5407714844,10.8203125, 0, 0,0, 0,0, 0,0 ); // TEAM_TWO
    AddPlayerClass( 277, 1764, 2068, 11, 0, 0,0, 0,0, 0,0 ); // TEAM_THREE
    AddPlayerClass( 164, 2416, 1125, 11, 0, 0,0, 0,0, 0,0 ); // TEAM_FOUR
	CreateStaticOwnedCar("Chatfort Police Dept.", 598, 2252.19995117,2478.10009766,10.69999981,180.00000000,-1,-1);
	//Cars//
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2256.19995117,2478.00000000,10.69999981,180.00000000,-1,-1); //Police Car (LVPD) ID 2
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2260.00000000,2477.80004883,10.69999981,180.00000000,-1,-1); //Police Car (LVPD) ID 3
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2268.50000000,2477.60009766,10.69999981,180.00000000,-1,-1); //Police Car (LVPD) ID 4
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2273.10009766,2477.39990234,10.69999981,180.00000000,-1,-1); //Police Car (LVPD)
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2278.00000000,2477.10009766,10.69999981,180.00000000,-1,-1); //Police Car (LVPD)
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2282.30004883,2477.39990234,10.69999981,180.00000000,-1,-1); //Police Car (LVPD)
	CreateStaticOwnedCar("Chatfort Police Dept.",427,2294.80004883,2476.39990234,11.10000038,180.00000000,-1,-1); //Enforcer
	CreateStaticOwnedCar("Chatfort Police Dept.",427,2290.60009766,2476.39990234,11.10000038,180.00000000,-1,-1); //Enforcer
	CreateStaticOwnedCar("Chatfort Police Dept.",601,2295.19995117,2443.39990234,10.80000019,0.00000000,-1,-1); //S.W.A.T. Van
	CreateStaticOwnedCar("Chatfort Police Dept.",601,2291.10009766,2444.10009766,10.80000019,0.00000000,-1,-1); //S.W.A.T. Van
	CreateStaticOwnedCar("Chatfort Police Dept.",599,2256.00000000,2458.30004883,11.19999981,180.00000000,-1,-1); //Police Ranger
	CreateStaticOwnedCar("Chatfort Police Dept.",599,2268.39990234,2458.89990234,11.19999981,180.00000000,-1,-1); //Police Ranger
	CreateStaticOwnedCar("Chatfort Police Dept.",599,2277.60009766,2458.89990234,11.19999981,180.00000000,-1,-1); //Police Ranger
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2282.00000000,2443.00000000,10.69999981,0.00000000,-1,-1); //Police Car (LVPD)
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2277.69995117,2442.89990234,10.69999981,0.00000000,-1,-1); //Police Car (LVPD)
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2273.50000000,2443.00000000,10.69999981,0.00000000,-1,-1); //Police Car (LVPD)
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2269.00000000,2443.10009766,10.69999981,0.00000000,-1,-1); //Police Car (LVPD)
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2260.19995117,2443.50000000,10.69999981,0.00000000,-1,-1); //Police Car (LVPD)
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2256.00000000,2443.39990234,10.69999981,0.00000000,-1,-1); //Police Car (LVPD)
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2251.69995117,2443.39990234,10.69999981,0.00000000,-1,-1); //Police Car (LVPD)
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2251.80004883,2458.19995117,10.69999981,0.00000000,-1,-1); //Police Car (LVPD)
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2260.69995117,2458.10009766,10.69999981,0.00000000,-1,-1); //Police Car (LVPD)
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2273.39990234,2458.50000000,10.69999981,0.00000000,-1,-1); //Police Car (LVPD)
	CreateStaticOwnedCar("Chatfort Police Dept.",598,2282.30004883,2458.50000000,10.69999981,0.00000000,-1,-1); //Police Car (LVPD)
	CreateStaticOwnedCar("Chatfort Police Dept.",490,2294.80004883,2458.19995117,11.10000038,0.00000000,-1,-1); //FBI Rancher
	CreateStaticOwnedCar("Chatfort Police Dept.",490,2290.89990234,2458.19995117,11.10000038,180.00000000,-1,-1); //FBI Rancher
	CreateStaticOwnedCar("Chatfort Fire Dept.",407,1769.69995117,2077.19995117,11.19999981,180.00000000,-1,-1); //Firetruck
	CreateStaticOwnedCar("Chatfort Fire Dept.",407,1763.19995117,2076.89990234,11.19999981,180.00000000,-1,-1); //Firetruck
	CreateStaticOwnedCar("Chatfort Fire Dept.",407,1757.50000000,2077.10009766,11.19999981,180.00000000,-1,-1); //Firetruck
	Cars[t31] =	AddStaticVehicleEx(544,1750.19995117,2074.30004883,11.19999981,180.00000000,-1,-1,3600); //Firetruck LA
	Cars[t32] =	AddStaticVehicleEx(416,1730.30004883,2080.89990234,11.10000038,270.00000000,-1,-1,3600); //Ambulance
	Cars[t33] =	AddStaticVehicleEx(416,1730.19995117,2076.80004883,11.10000038,270.00000000,-1,-1,3600); //Ambulance
	AddStaticVehicleEx(591,2855.10009766,895.59997559,10.80000019,0.00000000,-1,-1,3600); //Trailer 3
	AddStaticVehicleEx(591,2827.19995117,895.70001221,10.80000019,0.00000000,-1,-1,3600); //Trailer 3
	AddStaticVehicleEx(591,2818.00000000,895.50000000,10.80000019,0.00000000,-1,-1,3600); //Trailer 3
	AddStaticVehicleEx(515,2804.10009766,967.90002441,11.89999962,180.00000000,-1,-1,3600); //Roadtrain
	AddStaticVehicleEx(515,2825.00000000,967.70001221,11.89999962,180.00000000,-1,-1,3600); //Roadtrain
	AddStaticVehicleEx(515,2842.00000000,956.20001221,11.89999962,90.00000000,-1,-1,3600); //Roadtrain
	AddStaticVehicleEx(431,2774.19995117,1260.69995117,11.00000000,270.00000000,-1,-1,3600); //Bus
	AddStaticVehicleEx(431,2786.60009766,1260.80004883,11.00000000,270.00000000,-1,-1,3600); //Bus
	AddStaticVehicleEx(431,2799.10009766,1260.90002441,11.00000000,270.00000000,-1,-1,3600); //Bus
	AddStaticVehicleEx(431,2811.50000000,1260.90002441,11.00000000,270.00000000,-1,-1,3600); //Bus
	AddStaticVehicleEx(420,2833.30004883,1317.19995117,10.60000038,0.00000000,-1,-1,3600); //Taxi
	AddStaticVehicleEx(420,2833.30004883,1309.69995117,10.60000038,0.00000000,-1,-1,3600); //Taxi
	AddStaticVehicleEx(420,2833.30004883,1324.59997559,10.60000038,0.00000000,-1,-1,3600); //Taxi
	AddStaticVehicleEx(420,2833.39990234,1331.80004883,10.60000038,0.00000000,-1,-1,3600); //Taxi
	AddStaticVehicleEx(591,2818.10009766,853.59997559,10.80000019,180.00000000,-1,-1,3600); //Trailer 3
	AddStaticVehicleEx(591,2827.30004883,853.40002441,10.80000019,180.00000000,-1,-1,3600); //Trailer 3
	AddStaticVehicleEx(591,2855.19995117,852.79998779,10.80000019,180.00000000,-1,-1,3600); //Trailer 3
	AddStaticVehicleEx(515,2833.50000000,851.00000000,11.89999962,180.00000000,-1,-1,3600); //Roadtrain
	AddStaticVehicleEx(515,2838.60009766,851.00000000,11.89999962,180.00000000,-1,-1,3600); //Roadtrain
	AddStaticVehicleEx(515,2843.80004883,850.90002441,11.89999962,180.00000000,-1,-1,3600); //Roadtrain
	AddStaticVehicleEx(474,1695.40002441,1297.30004883,10.69999981,0.00000000,-1,-1,3600); //Hermes
	AddStaticVehicleEx(401,1692.30004883,1297.19995117,10.69999981,0.00000000,-1,-1,3600); //Bravura
	AddStaticVehicleEx(496,1669.69995117,1297.30004883,10.60000038,0.00000000,-1,-1,3600); //Blista Compact
	AddStaticVehicleEx(567,1682.50000000,1306.19995117,10.80000019,0.00000000,-1,-1,3600); //Savanna
	AddStaticVehicleEx(445,1695.40002441,1306.09997559,10.80000019,0.00000000,-1,-1,3600); //Admiral
	AddStaticVehicleEx(547,1692.19995117,1306.00000000,10.69999981,0.00000000,-1,-1,3600); //Primo
	AddStaticVehicleEx(516,1689.09997559,1306.09997559,10.69999981,0.00000000,-1,-1,3600); //Nebula
	AddStaticVehicleEx(467,1688.90002441,1297.59997559,10.69999981,0.00000000,-1,-1,3600); //Oceanic
	AddStaticVehicleEx(525,1743.59997559,1885.69995117,10.80000019,90.00000000,-1,-1,3600); //Tow Truck
	AddStaticVehicleEx(525,1743.90002441,1889.80004883,10.80000019,90.00000000,-1,-1,3600); //Tow Truck
	AddStaticVehicleEx(525,1744.09997559,1894.09997559,10.80000019,90.00000000,-1,-1,3600); //Tow Truck
	AddStaticVehicleEx(525,1744.30004883,1898.40002441,10.80000019,90.00000000,-1,-1,3600); //Tow Truck
	AddStaticVehicleEx(530,1736.59997559,1854.19995117,10.60000038,0.00000000,-1,-1,3600); //Forklift
	AddStaticVehicleEx(530,1734.09997559,1854.40002441,10.60000038,0.00000000,-1,-1,3600); //Forklift
	AddStaticVehicleEx(530,1739.19995117,1854.30004883,10.60000038,0.00000000,-1,-1,3600); //Forklift
	Cars[t34] =	AddStaticVehicleEx(409,2422.50000000,1114.50000000,10.60000038,180.00000000,1,7,3600); //Stretch
	Cars[t35] =	AddStaticVehicleEx(409,2422.69995117,1132.69995117,10.60000038,180.00000000,1,7,3600); //Stretch
	Cars[t36] =	AddStaticVehicleEx(490,2422.60009766,1123.80004883,11.00000000,180.00000000,1,7,3600); //FBI Rancher
	Cars[t37] =	AddStaticVehicleEx(490,2422.80004883,1105.90002441,11.00000000,180.00000000,1,7,3600); //FBI Rancher
	Cars[t38] =	AddStaticVehicleEx(490,2423.19995117,1143.09997559,11.00000000,180.00000000,1,7,3600); //FBI Rancher
	Cars[t39] =	AddStaticVehicleEx(525,2298.00000000,2452.30004883,3.29999995,270.00000000,1,2,3600); //Tow Truck
	Cars[t40] =	AddStaticVehicleEx(525,2298.00000000,2455.80004883,3.29999995,270.00000000,1,2,3600); //Tow Truck
	Cars[t41] =	AddStaticVehicleEx(525,2298.10009766,2459.80004883,3.29999995,270.00000000,1,2,3600); //Tow Truck
	CreateObject(4514,1806.80004883,809.59997559,11.80000019,359.00000000,0.00000000,0.00000000); //object(cn2_roadblock01ld) (1)
	CreateObject(4514,1787.80004883,810.20001221,11.80000019,0.00000000,0.00000000,0.00000000); //object(cn2_roadblock01ld) (2)
	CreateObject(4514,1403.90002441,873.90002441,7.80000019,0.00000000,0.00000000,235.00000000); //object(cn2_roadblock01ld) (3)
	CreateObject(4514,1319.50000000,833.70001221,8.10000038,0.00000000,0.00000000,270.00000000); //object(cn2_roadblock01ld) (4)
	CreateObject(4514,1198.40002441,975.09997559,8.50000000,0.00000000,0.00000000,342.00000000); //object(cn2_roadblock01ld) (5)
	CreateObject(4514,1255.19995117,1097.09997559,8.50000000,0.00000000,0.00000000,40.00000000); //object(cn2_roadblock01ld) (6)
	CreateObject(4514,1255.30004883,2210.39990234,8.50000000,0.00000000,0.00000000,140.00000000); //object(cn2_roadblock01ld) (7)
	CreateObject(4514,1197.40002441,2334.60009766,8.60000038,0.00000000,0.00000000,200.00000000); //object(cn2_roadblock01ld) (8)
	CreateObject(4514,1314.50000000,2473.60009766,8.19999981,0.00000000,0.00000000,270.00000000); //object(cn2_roadblock01ld) (9)
	CreateObject(4514,1400.69995117,2431.30004883,7.89999962,0.00000000,0.00000000,300.00000000); //object(cn2_roadblock01ld) (10)
	CreateObject(1238,2425.69995117,1143.30004883,10.00000000,0.00000000,0.00000000,0.00000000); //object(trafficcone) (6)
	CreateObject(1238,2423.19995117,1149.50000000,10.00000000,0.00000000,0.00000000,0.00000000); //object(trafficcone) (7)
	CreateObject(1238,2425.59960938,1144.69921875,10.00000000,0.00000000,0.00000000,0.00000000); //object(trafficcone) (8)
	CreateObject(1238,2425.50000000,1145.89941406,10.00000000,0.00000000,0.00000000,0.00000000); //object(trafficcone) (9)
	CreateObject(1238,2425.19921875,1146.89941406,10.00000000,0.00000000,0.00000000,0.00000000); //object(trafficcone) (10)
	CreateObject(1238,2424.79980469,1147.69921875,10.00000000,0.00000000,0.00000000,0.00000000); //object(trafficcone) (11)
	CreateObject(1238,2424.39941406,1148.39941406,10.00000000,0.00000000,0.00000000,0.00000000); //object(trafficcone) (12)
	CreateObject(1238,2423.89941406,1149.00000000,10.00000000,0.00000000,0.00000000,0.00000000); //object(trafficcone) (13)*/
	SetGameModeText("Chatford City RP Rev 19");
	AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
	ManualVehicleEngineAndLights();
	return 1;
}

public OnGameModeExit()
{
	return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
	SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
	SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
	return 1;
}

public OnPlayerConnect(playerid)
{
	TruckerOnJob[playerid] = 0; //Player is not working as a trucker
  Cuffed[playerid] = 0; //player is not cuffed
	pTazed[playerid] = 0; //players not tazed
	isPlayerSpectating[playerid] = 0; // you're not spectating
	HandsUp[playerid] = 0; //you don't have your hands up.
	SetPlayerColor(playerid, COLOR_INVISIBLE); //Set their color to invisible so they're not on the map.
	SendClientMessage(playerid, 0xFF00FFFF, "Chatford Roleplay, Revision 24"); //welcome
    if(fexist(UserPath(playerid))) //check to see if the player exists in the database.
    {
        INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
        ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit"); //you are, good, please sign in
    }
    else
    {
        ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit"); //you're not? register please.
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new INI:File = INI_Open(UserPath(playerid)), Float:pX, Float:pY, Float:pZ; //write out all the data to the ini
    GetPlayerPos(playerid, pX, pY, pZ);
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File,"Faction",PlayerInfo[playerid][pFaction]);
    INI_WriteInt(File,"Rank",PlayerInfo[playerid][pRank]);
    INI_WriteFloat(File,"X",pX, 50);
    INI_WriteFloat(File,"Y",pY, 50);
    INI_WriteFloat(File,"Z",pZ, 50);
	INI_WriteInt(File,"Skin",GetPlayerSkin(playerid));
    INI_Close(File);
	Logged[playerid] = 0;
    return 1;
}

public OnPlayerSpawn(playerid)
{
	if(PlayerInfo[playerid][pPosX] == 0) // If you don't have coords, spawn here.
	{
		SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
	}
	else //If you do....
	{
		if(Logged[playerid] == 1) //and you're logged in(AKA YOU'VE DIED.)
 		{
	    	SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    	}
    	else //spawn them where they were at....added .5 to the z because you sometimes spawn inside of stuff.
    	{
		SetPlayerPos(playerid, PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ] + 0.5);
		Logged[playerid] = 1;
		}
	}
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
	SetSpawnInfo( playerid, 0, 0, 1958.3783, 1343.1572, 15.3746, 269.15, 0, 0, 0, 0, 0, 0 ); //what does this even do I don't know.
    PlayerInfo[killerid][pKills]++;
    PlayerInfo[playerid][pDeaths]++;
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
	return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
	return 1;
}

public OnPlayerText(playerid, text[]) //Changes player text from being "Jeffrey_Mason says: lol" to "Jeffrey Mason says: lol"
{
    new message[128];
    format(message, sizeof(message), "%s says: %s", GetName(playerid), text);
    ProxDetector(30.0, playerid, message, -1);
    return 0;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/mycommand", cmdtext, true, 10) == 0)
	{
		// Do something here
		return 1;
	}
	return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	PlayerInCar(playerid, vehicleid);//OH THAT'S WHAT THIS DOES, LOL, MAKES AN ARRAY OF WHOSE IN WHAT CAR. good idea.
	return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
	PlayerInCar(playerid, 0);
	return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate) // faction based cars.
{

    if(newstate == 2)
    {
      		new CarCheck = GetPlayerVehicleID(playerid);
			new ModelCheck = GetVehicleModel(CarCheck);
			if(ModelCheck == 427 || ModelCheck == 497 || ModelCheck == 528 || ModelCheck == 596 || ModelCheck == 597 || ModelCheck == 598 || ModelCheck == 599 || ModelCheck == 601)
			{
				if(PlayerInfo[playerid][pFaction] != 2)
					{
						RemovePlayerFromVehicle(playerid);
						SendClientMessage(playerid, COLOR_RED, "You don't have the keys for this car.");
            			return 1;
					}
			}
			else if(ModelCheck == 416 || ModelCheck == 544 || ModelCheck == 407)
			{
				if(PlayerInfo[playerid][pFaction] != 3 || PlayerInfo[playerid][pAdmin] <= 0)
				{
					RemovePlayerFromVehicle(playerid);
					SendClientMessage(playerid, COLOR_RED, "You don't have the keys for this car.");
					return 1;
				}
			}
			else if(strcmp(CarInfo[CarCheck][cOwner], GetName(playerid)) != 0)
			{
			    new string[180];
			    format(string, sizeof(string), "This car belongs to %s, you are %s! This is vehicle %i.", CarInfo[CarCheck][cOwner], GetName(playerid), CarInfo[CarCheck][cModel]);
			    SendClientMessage(playerid, COLOR_RED, string);
				RemovePlayerFromVehicle(playerid);
				SendClientMessage(playerid, COLOR_RED, "This isn't your car.");
				return 1;
			}

	}
	return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
	  new vehicleid = GetPlayerVehicleID(playerid);
		new modelid = GetVehicleModel(vehicleid);
		new Seatid = GetPlayerVehicleSeat(playerid);
    new string[ 128 ];
		if(modelid == 515 || modelid == 403 || modelid == 514)
	   {
			if(Seatid == 0)
			{
    		  if(IsTrailerAttachedToVehicle(vehicleid) == 0)
				{
					SendClientMessage(playerid, COLOR_RED, "You need to drop off the goods if you want to get paid!");
					return 1;
				}
				else
				if(IsTrailerAttachedToVehicle(vehicleid) == 1)
				{
					if(TruckerOnJob[playerid] == 1)
					{
            if(trailervin[vehicleid] == GetVehicleTrailer(vehicleid))
						{
                            
							TogglePlayerControllable(playerid, false);
              SetTimerEx("Unfreeze", 7500, false, "i", playerid);
							GivePlayerMoney(playerid, 10000);
    					 DisablePlayerCheckpoint(playerid);
							TruckerOnJob[playerid] = 0;
              format(string, sizeof(string), "* %s puts the parking break on while crew workers unload the trailer.", GetName(playerid));
               ProxDetector(30, playerid, string, COLOR_PURPLE);
							return 1;
						}
						else
						if(trailervin[vehicleid] != GetVehicleTrailer(vehicleid))
						{
						  SendClientMessage(playerid, COLOR_RED, "You have the wrong trailer!");
							return 1;
						}
					}
				}
			}
		}
		return 1;
}

public Unfreeze(playerid)
{
  new string[ 128 ];
	TogglePlayerControllable(playerid, true); // Unfreeze the player after 5 seconds
	format(string, sizeof(string), "* %s releases the parking break and drives off.", GetName(playerid));
	ProxDetector(30, playerid, string, COLOR_PURPLE);
	return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
	return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
	return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
	return 1;
}

public OnRconCommand(cmd[])
{
	return 1;
}

public OnPlayerRequestSpawn(playerid)
{
 //-----------------------------------------------------------------------------
	return 1;
}

public OnObjectMoved(objectid)
{
	return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
	return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
	return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
	return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
	return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
	return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
	return 1;
}

public OnPlayerExitedMenu(playerid)
{
	return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
	return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
	return 1;
}

public OnPlayerUpdate(playerid)
{
	return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
	return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
	return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
	return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
	return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) // all the login and register crap.
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",0);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
				INI_WriteInt(File,"Faction",0);
				INI_WriteInt(File,"Rank",0);
				INI_WriteInt(File,"X",0);
				INI_WriteInt(File,"Y",0);
				INI_WriteInt(File,"Z",0);
				INI_WriteInt(File,"Skin", 46);
                INI_Close(File);

                SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
                SpawnPlayer(playerid);
                ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You've successfully registered on the server.","Ok","");
            }
        }

        case DIALOG_LOGIN:
        {
            if ( !response ) return Kick ( playerid );
            if( response )
            {
                if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
                {
                    INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
                    GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
                    ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
    }
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
	return 1;
}

public Tazed(playerid) //Stop being tazed plz.
{
      pTazed[playerid] = 0;
      TogglePlayerControllable(playerid, true);
      ClearAnimations(playerid);
      return 1;
}

public OnPlayerShootPlayer(Shooter,Target,Float:HealthLost,Float:ArmourLost)
{
    if(PlayerInfo[Shooter][pFaction] == 2)
    {
        new string[ 128 ];
        if(GetPlayerWeapon(Shooter) == 23)
		{
			TogglePlayerControllable(Target, false);
            ApplyAnimation(Target,"CRACK","crckdeth2",4.1,1,1,1,1,1);
            pTazed[Target] = 1;
            SetTimerEx("Tazed", 10000, 0, "d", Target);
            SendClientMessage(Target, 0xFF0000FF, "You've been tazed!");
            format(string, sizeof(string), "* %s aims their tazer on %s and tazes them.", GetName(Shooter), GetName(Target));
            ProxDetector(30, Shooter, string, COLOR_PURPLE);
        }
    }
    return 1;
}
//----------------------------------------------------------------------------------------------//
//---------------------						GENERIC COMMANDS		        --------------------//
//----------------------------------------------------------------------------------------------//
COMMAND:engine(playerid, params[]) //engine command
{
	if(GetPlayerState(playerid) == 2) //is player driving?
	{
		if(IsEngineRunning(GetPlayerVehicleID(playerid))) //is the engine running?
		{
			SetVehicleParamsEx(GetPlayerVehicleID(playerid), 0, 0, 0, 0, 0, 0, 0); //well turn it off..
			SendClientMessage(playerid, COLOR_ORANGE, "You've shut this vehicle off."); // notify the user they've done a good job.
		}
		else if(!IsEngineRunning(GetPlayerVehicleID(playerid))) //is the engine running? no?
		{
			SetVehicleParamsEx(GetPlayerVehicleID(playerid), 1, AreLightsOn(GetPlayerVehicleID(playerid)), 0, 0, 0, 0, 0); //turn it on.
			SendClientMessage(playerid, COLOR_GREEN, "You've successfully started this vehicle."); //again, notify the user they've done a good job.
		}
	}
	else
	{
		SendClientMessage(playerid, COLOR_YELLOW, "You're not in a vehicle."); //stupid.
	}
	return 1;
}
COMMAND:lights(playerid, params[]) //lights command
{
	if(GetPlayerState(playerid) == 2) //driver
	{
		if(AreLightsOn(GetPlayerVehicleID(playerid))) //lights are on
		{
			SendClientMessage(playerid, COLOR_GREEN, "You've turned off the lights."); //their off now.
			SetVehicleParamsEx(GetPlayerVehicleID(playerid), IsEngineRunning(GetPlayerVehicleID(playerid)), 0, 0, 0, 0, 0, 0); //turn them off.
		}
		else if(!AreLightsOn(GetPlayerVehicleID(playerid))) //otherwise turn them on
		{
			SendClientMessage(playerid, COLOR_GREEN, "You've turned on the lights.");
			SetVehicleParamsEx(GetPlayerVehicleID(playerid), IsEngineRunning(GetPlayerVehicleID(playerid)), 1, 0, 0, 0, 0, 0);
		}
	}
	else if(IsPlayerInAnyVehicle(playerid))
	{
		SendClientMessage(playerid, COLOR_ORANGE, "You're not driving the car."); //stupid.
	}
	else
	{
		SendClientMessage(playerid, COLOR_ORANGE, "You're not in  vehicle"); //....what lights are you trying to turn on I don't even
	}
	return 1;
}

COMMAND:r(playerid, params[]) //radio command.
{
	new string[150], text[150], fact;
	if(PlayerInfo[playerid][pFaction] == 0) //you're not in a faction.
	{
		return 0;
	}
	else if(sscanf(params, "s", text)) //make sure text was entered into the /r command
	{
		SendClientMessage(playerid, -1, "USAGE: /r [text]");
	}
	else
	{
			fact = PlayerInfo[playerid][pFaction]; //get the faction ID, I guess I could just FactionMessenger(playerid, PlayerInfo[playerid][pFaction], string, COLOR_BLUE)
			format(string, sizeof(string), "((COM)) %s : %s, over.", GetName(playerid), text);
			FactionMessenger(fact, string, COLOR_BLUE);
	}
	return 1;
}


COMMAND:me(playerid, params[]) //your actions.
{
	new string[128], action[100];
	if(sscanf(params, "s", action)) //make sure theres text.
	{
		SendClientMessage(playerid, -1, "USAGE: /me [text]");
	}
	else
	{
		format(string, sizeof(string), "* %s %s", GetName(playerid), action); //format it so it looks like *name [text]
		ProxDetector(20, playerid, string, COLOR_PURPLE); //send the message to local players.
	}
	return 1;
}

COMMAND:do(playerid, params[]) //what other people percieve
{
	new string[128], action[100];
	if(sscanf(params, "s", action)) //did you enter text?
	{
		SendClientMessage(playerid, -1, "USAGE: /do [text]");
	}
	else
	{
		format(string, sizeof(string), "* %s ((%s))", action, GetName(playerid)); //see me, does the same thing except with different format.
		ProxDetector(20, playerid, string, COLOR_PURPLE);
	}
	return 1;
}

COMMAND:shout(playerid, params[]) //shouting command
{
	new string[128], action[100];
	if(sscanf(params, "s", action))
	{
		SendClientMessage(playerid, -1, "USAGE: /(s)hout [text]");
	}
	else
	{
		format(string, sizeof(string), "%s shouts: %s", GetName(playerid), action);
		ProxDetector(40, playerid, string, COLOR_PURPLE);
	}
	return 1;
}

COMMAND:s(playerid, params[])
{
	new string[128], action[100];
	if(sscanf(params, "s", action))
	{
		SendClientMessage(playerid, -1, "USAGE: /(s)hout [text]");
	}
	else
	{
		format(string, sizeof(string), "%s shouts: %s", GetName(playerid), action);
		ProxDetector(40, playerid, string, COLOR_PURPLE);
	}
	return 1;
}
COMMAND:o(playerid, params[]) //GLOBAL OOC
{
	new string[128], text[100]; //defines
	if(sscanf(params, "s", text)) //check to see if params were entered
	{
		SendClientMessage(playerid, -1, "USAGE: /o [text]"); //if they werent tell them how to use the command.
	}
	else //if it has paramaters
	{
		format(string, sizeof(string), "((GLOBAL))%s says: %s", GetName(playerid), text); //format the username and text into the string.
		SendClientMessageToAll(COLOR_GREY, string); //sends the recently modified string to everyone.
	}
	return 1;
}

COMMAND:handsup(playerid, params[]) //THIS WAS A PROOF OF CONCEPT, AND SHOULD NOT BE TAKEN AS A SERIOUS COMMAND, yet.
{
	if(IsPlayerInAnyVehicle(playerid) == 0)
	{
		TogglePlayerHands(playerid);
	}
	return 1;
}

COMMAND:help(playerid, params[]) //help command BY Koty McRae
{
	if(IsPlayerConnected(playerid))
	{
        SendClientMessage(playerid, COLOR_LIGHTBLUE,":: CHAT :: (/o ooc)(/me)(/do)(/shout or /s)(/w whisper)(/l local) ");
        SendClientMessage(playerid, COLOR_LIGHTBLUE,":: VEHICLE :: (/engine) ");
	}
	return 1;
}
//----------------------------------------------------------------------------------------------//
//---------------------			GET RID OF THIS COMMAND BEFORE RELEASE.     --------------------//
//----------------------------------------------------------------------------------------------//
COMMAND:spawncar(playerid, params[])
{
	new carid, Float:x, Float:y, Float:z;
	if(!sscanf(params, "i", carid))
	{
		GetPlayerPos(playerid, Float:x, Float:y, Float:z);
		CreateVehicle(carid, x, y, z, 0, 0, 3600);
	}
	else
	{
		SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /spawncar [modelid]");
	}
	return 1;
}
COMMAND:spawnownedcar(playerid, params[])
{
	new ownerid, modelid, Float:x, Float:y, Float:z, color1, color2, carid;
	if(!sscanf(params, "iiii", ownerid, modelid, color1, color2))
	{
		GetPlayerPos(playerid, x, y, z);
		carid = CreateOwnedCar(ownerid, modelid, x, y, z, color1, color2);
		SendClientMessage(playerid, COLOR_RED, CarInfo[carid][cModel]);
		return 1;

	}
	else if(sscanf(params, "iiii", ownerid, modelid, color1, color2))
	{
		SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /spawnownedcar [ownerid] [modelid] [color1] [color2]");
		return 1;
	}
}
//----------------------------------------------------------------------------------------------//
//---------------------			GET RID OF THIS COMMAND BEFORE RELEASE.     --------------------//
//----------------------------------------------------------------------------------------------//

//----------------------------------------------------------------------------------------------//
//---------------------					END GENERIC COMMANDS                --------------------//
//----------------------------------------------------------------------------------------------//
CMD:trucker(playerid, params[])
{
  	  new vehicleid = GetPlayerVehicleID(playerid);
		 new modelid = GetVehicleModel(vehicleid);
		 new Seatid = GetPlayerVehicleSeat(playerid);
     new int = random(5);
  	  new truck = GetPlayerVehicleID(playerid);
     if(modelid == 515 || modelid == 403 || modelid == 514)
	 	{
			if(Seatid == 1)
  		 {
				SendClientMessage(playerid, COLOR_RED, "You need to be in the driver seat to start a job!");
				return 1;
  		 }
			else
			if(Seatid == 0)
			{
				if(IsTrailerAttachedToVehicle(truck) == 0)
				{
					SendClientMessage(playerid, COLOR_RED, "You need a trailer!");
					return 1;
				}
				else
				if(IsTrailerAttachedToVehicle(truck) == 1)
				{
					if(TruckerOnJob[playerid] == 1)
					{
						SendClientMessage(playerid, COLOR_RED, "You are already on a job! Finish your current job or type /quitjob.");
						return 1;
					}
					else
					if(TruckerOnJob[playerid] == 0)
					{
            SendClientMessage(playerid, COLOR_GREEN, "Go to your drop off point! (GPS Marker)");
						trailervin[truck] = GetVehicleTrailer(truck);
						TruckerOnJob[playerid] = 1;
						switch(int)
						{
							case 0:
							{
								SetPlayerCheckpoint(playerid, 2310.396484375, 1796.0393066406, 10.8203125, 3.0);
							}
							case 1:
							{
								SetPlayerCheckpoint(playerid, 2569.9638671875, 1898.0933837891, 10.822219848633, 3.0);
							}
							case 2:
							{
								SetPlayerCheckpoint(playerid, 2787.0500488281, 2561.4255371094, 9.9960956573486, 3.0);
							}
							case 3:
							{
								SetPlayerCheckpoint(playerid, 2278.3000488281, 2787.7346191406, 10.8203125, 3.0);
							}
							case 4:
							{
								SetPlayerCheckpoint(playerid, 1678.0111083984, 2340.1508789063, 9.9510116577148, 3.0);
							}
						}
					}
				}
			}
		}
		return 1;
}

//------------------------------------------------------------------------------------------------------------------
//------------------------------                POLICE COMMANDS                        -----------------------------
//------------------------------------------------------------------------------------------------------------------
CMD:tazer(playerid, params[])
{
		if(PlayerInfo[playerid][pFaction] == 2)
		{
            new string[ 128 ];

			{
                if(IsPlayerInAnyVehicle(playerid)) // Checks if the player is in a vehicle.
                SendClientMessage(playerid, 0xFF0000FF, "You can't use this command while in a car!");
       		}
        	if(pTazer[playerid] == 0) // If the player has no tazer withdrawn.
			{
              GivePlayerWeapon(playerid, 23, 20); // Gives a SD.
              pTazer[playerid] = 1; // Sets the var to true.
              format(string, sizeof(string), "* %s takes out their tazer from their holster and loads it.", GetName(playerid));
              ProxDetector(30, playerid, string, COLOR_PURPLE);
			}

           	else
           	if(pTazer[playerid] == 1) // If the player has the tazer withdrawn to holster it.
			{
              GivePlayerWeapon(playerid, 24, 100); // Gives a deagle.
              pTazer[playerid] = 0; // Sets the var to false.
              format(string, sizeof(string), "* %s unloads their tazer and puts it back to their holster.", GetName(playerid));
              ProxDetector(30, playerid, string, COLOR_PURPLE);
   			}
		}
		return 1;
}

CMD:duty(playerid, params[]) //Doesnt need params function
{
   	new Float:x,Float:y,Float:z;
	new skin[MAX_PLAYERS];
	if(PlayerInfo[playerid][pFaction] ==2)
	{
		if (duty[playerid] == 0) //Check if player is on duty
		{
			skin[playerid] = GetPlayerSkin(playerid);
            GivePlayerWeapon(playerid, 3, 100);
			GivePlayerWeapon(playerid, 24, 50);
            GivePlayerWeapon(playerid, 31, 300);
			GetPlayerPos(playerid,x,y,z); //Looks for players position
	        SetPlayerHealth(playerid,100); //makes player godmode
	        SetPlayerSkin(playerid,280); //set admin skin to 294
	        duty[playerid] = 1; //Set player on duty
			return 1;
	    }
	    else
		if (duty[playerid] == 1) //Check if player is on duty
	    {
     		ResetPlayerWeapons(playerid);
			SetPlayerHealth(playerid,100); //sets player health back to 100
			SetPlayerSkin(playerid, skin[playerid]);
	        duty[playerid] = 0;
			return 1;
	    }
	}
    return 1;
}

//-------------------------------------------------------------------------------------------------------------------
//------------------------------					ADMIN SYSTEM                       ------------------------------
//-------------------------------------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------------------------------------
//------------------------------			ADMIN SYSTEM     LEVEL 2                   ------------------------------
//-------------------------------------------------------------------------------------------------------------------
CMD:spectate(playerid, params[])
{
	if(PlayerInfo[playerid][pAdmin] > 2)
	{
	    if(aDuty[playerid] == 1)
	    {
			new specid;
			if(!sscanf(params, "i", specid))
			{
				ToggleSpectate(playerid, specid);
				return 1;
			}
			else if(sscanf(params, "i", specid))
			{
				SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /spectate [playerid]");
				return 1;
			}
		}
		else if(aDuty[playerid] == 0)
		{
		    SendClientMessage(playerid, COLOR_GREY, "You're not on admin duty, silly");
  		}
	}
	else
	{
		return 0;
	}
}
CMD:aduty(playerid, params[]) //Doesnt need params function
{
   	new Float:x,Float:y,Float:z;
	new Text3D:label = Create3DTextLabel("Admin On Duty!", COLOR_RED,x,y,z, 40.0, 0, 0); //Creates 3d text label at player position
	new skin[MAX_PLAYERS];
	new string[128];
	if(PlayerInfo[playerid][pAdmin] >=1 || IsPlayerAdmin(playerid)) //If you use rcon admin delete (PlayerInfo[playerid][pAdmin] >=1 ||
	{
		if (aDuty[playerid] == 0) //Check if player is on duty
		{
			skin[playerid] = GetPlayerSkin(playerid);

	       	GetPlayerPos(playerid,x,y,z); //Looks for players position
	        SetPlayerHealth(playerid,999999); //makes player godmode
	        SetPlayerColor(playerid,COLOR_RED); //set admin colour red
	        SetPlayerSkin(playerid,217); //set admin skin to 294
	        format(string,sizeof(string), "%s is now on Duty!",GetName(playerid)); //here you format string to send to players
			AdminMessenger(COLOR_RED, string);
	        Attach3DTextLabelToPlayer(label,playerid,0.0, 0.0, 0.7); //attach 3d text label made before to player
	        aDuty[playerid] = 1; //Set player on duty
			return 1;
	    }
	    else if (aDuty[playerid] == 1) //Check if player is on duty
	    {
	        Delete3DTextLabel(label); //Delete 3d text label saying "Admin On Duty!"
	        SetPlayerHealth(playerid,100); //sets player health back to 100
			SetPlayerSkin(playerid, skin[playerid]);
	        format(string,sizeof(string)," %s is now off Duty!",GetName(playerid)); //Format string to send to players
			AdminMessenger(COLOR_RED, string);
	        aDuty[playerid] = 0; //sets admin off duty
			return 1;
	    }
	}
	else
 {
 }
    return 0;
}

CMD:goto(playerid, params[])
{
	new teleid, telename[24], string[100], Float:x, Float:y, Float:z;
	if(PlayerInfo[playerid][pAdmin] > 1)
	{
	    if(aDuty[playerid] == 1)
	    {
			if(!sscanf(params, "i", teleid))
			{
				GetPlayerPos(teleid, x, y, z);
				SetPlayerPos(playerid, x, y, z);
				telename = GetName(teleid);
				format(string, sizeof(string), "You've teleported to %s.", telename);
				SendClientMessage(playerid, COLOR_YELLOW, string);
				return 1;
			}
			else if(sscanf(params, "i", teleid))
			{
				SendClientMessage(playerid, COLOR_ORANGE, "USAGE: /goto [playerid]");
				return 1;
			}
		}
		else if(aDuty[playerid] == 0)
		{
		    SendClientMessage(playerid, COLOR_GREY, "You're not on admin duty, silly");
			return 1;
  		}
	}
	else
	{
		return 0;
	}
}





















